<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改区域')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-area-edit" th:object="${area}">
            <input id="areaId" name="id" th:field="*{id}" type="hidden">
            <input id="treeId" name="pid" type="hidden" th:value="*{pid}" />
            <div class="form-group">
                <label class="col-sm-3 control-label">上级菜单：</label>
                <div class="col-sm-8">
                    <div class="input-group">
                        <input class="form-control" type="text" onclick="selectAreaTree()" id="treeName" readonly="true" th:value="${pAreaName}">
                        <span class="input-group-addon"><i class="fa fa-search"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">区域名称：</label>
                <div class="col-sm-8">
                    <input name="areaName" th:field="*{areaName}" class="form-control" type="text" required>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script type="text/javascript">
        var prefix = ctx + "system/area";

        /*菜单管理-新增-选择区域树*/
        function selectAreaTree() {
            var areaId = $("#treeId").val();
            var areaId = areaId > 0 ? areaId : 1;
            var url = prefix + "/areaTree/" + areaId;
            var options = {
                title: '菜单选择',
                width: "380",
                url: url,
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        }

        // 弹窗选择后回调
        function doSubmit(index, layero){
            var body = layer.getChildFrame('body', index);
            // console.log("treeId", body.find('#treeId').val());
            // console.log("treeName", body.find('#treeName').val());
            var pid = body.find('#treeId').val();
            var id = $("#areaId").val();
            if (pid == id) {
                layer.close(index);
                $.modal.alertError("父级不能选择自己");
                return;
            }
            $("#treeId").val(body.find('#treeId').val());
            $("#treeName").val(body.find('#treeName').val());
            layer.close(index);
        }

        $("#form-area-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-area-edit').serialize());
            }
        }
    </script>
</body>
</html>